<?php
namespace app\html5\controller;
use app\Db2;
use app\H5AuthController;

class Yaoshi extends H5AuthController{
    //获取待处理药方
    public function get_yaofang_list(){
        // $user = $this->user;
        // $id = input('id');
        $city = input('city');
        // $type = input('type ');

        // if(!$id || $id == 'undefined') return rejson(302,'id不能为空');

        // $where = [
        //     'id' => $id
        // ];

        // $data =  Db2::get_datalist("zhenduanjilu",[['yfid'=>$id]],['id','name'],);

        // return rejson(200, '操作成功', $data);
        
        $user = $this->user;// 获取当前用户信息
        // print_r($user);
        $curpage = input('curpage');
        $listnum = input('listnum');

        $curpage = $curpage?$curpage:0;
        $listnum = $listnum?$listnum:20;

        $where = [];
        if($user['type']==5||$user['type']==3){
            // 只有管理员和药师能查看

            $where = [
                [
                    'status'=>1,
                    'step'=>4,
                ],
            ];
        }else{
            return rejson(302,'没有权限');
        }


        $list = Db2::get_datalist_page("zhenduanjilu",$where,$curpage,$listnum,null,'id desc');
        
        $datalist = $list['datalist'];
        
        $ids = array_column($datalist,'userid');
        
        $userlist = Db2::get_datalist("user",['id in ('.implode($ids,',').')']);
        
        foreach ($datalist as &$item){
            foreach ($userlist as $user){
                if($item['userid']==$user['id']){
                    $item['user'] = $user;
                }
            }
        }
        
        $list['datalist'] = $datalist;

        // print_r($userlist);die;

        return rejson(200, '操作成功', $list);
    }
    //查看药方详情
    public function get_yaofang(){
        $user = $this->user;
        $id = input('id');
        // $city = input('city');
        // $type = input('type ');

        if(!$id || $id == 'undefined') return rejson(302,'id不能为空');
        
        if($user['type']==5||$user['type']==3){
            // 只有管理员和药师能查看

            $where = [
                'id' => $id,
                'status'=>1,
                'step'=>4,
            ];
        }else{
            return rejson(302,'没有权限');
        }

        $data =  Db2::get_data("zhenduanjilu",[$where]);

        $user = Db2::get_data("user",[['id' => $data['userid']]]);

        $data['user'] = $user;
        // print_r($data);die;

        return rejson(200, '操作成功', $data);
    }
}

